<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn1">按钮1</button>
    <button id="btn2">按钮2</button>
    <button onclick="xxx()">按钮3</button>

    <script>
      const btn1 = document.querySelector("#btn1");
      btn1.addEventListener("click", () => {
        alert("按钮1 被点击le ");
      });

      const btn2 = document.querySelector("#btn2");
      btn2.onclick = () => {
        alert("按钮2 被点了");
      };

      function xxx() {
        alert("按钮3 被点了");
      }

      const obj = {
        xxx() {
          console.log(this);
        },
      };

      // obj.xxx() // obj

      const onClick = obj.xxx;
      onClick(); // window
    </script>
  </body>
</html>
